package com.xiaoma.tpo.dao;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.ClsClass;
import com.xiaoma.tpo.dto.ClsClassVo;
import com.xiaoma.tpo.utils.Pager;

@Repository
public class ClsClassDao extends BaseDaoImpl<ClsClass> {

    
    private static final Logger LOG = LoggerFactory.getLogger(ClsClassDao.class);
    @SuppressWarnings("unchecked")
    public List<ClsClassVo> findAllWithUserCount() {
        String sql = "select a.* ,count(b.cls_class_id) user_count from cls_class a left join cls_user_class b on a.id = b.cls_class_id group by a.id order by a.seq_num asc";
        LOG.info("SQL:{}", sql);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(ClsClassVo.class, getNameHandler()));
        return (List<ClsClassVo>)result;
    }
    //只要 机经
	public List<ClsClassVo> findAllWithUserCountOnlyForecast() {
		String sql = "select a.* ,count(b.cls_class_id) user_count from cls_class a left join cls_user_class b on a.id = b.cls_class_id where a.type = '1' group by a.id order by a.seq_num asc";
        LOG.info("SQL:{}", sql);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(ClsClassVo.class, getNameHandler()));
        return (List<ClsClassVo>)result;
	}
	public List<ClsClassVo> findAllWithUserCountNoForecast() {
		String sql = "select a.* ,count(b.cls_class_id) user_count from cls_class a left join cls_user_class b on a.id = b.cls_class_id  where a.type='0' group by a.id order by a.seq_num asc";
        LOG.info("SQL:{}", sql);
        List<?> result = jdbcTemplate.query(sql, new DefaultRowMapper(ClsClassVo.class, getNameHandler()));
        return (List<ClsClassVo>)result;
	}
}
